<%--
  活动主页面
  User: kent
  Date: 15/10/20
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="packtag" prefix="pack" %>
<c:set var="ctx" value="${pageContext.request.contextPath }"/>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

    <pack:style>
        <src>/static/weui/css/weui.min.css</src>
        <src>/static/css/activity/style.css</src>
        <src>/static/sweetalert/sweetalert.css</src>
    </pack:style>

    <pack:script>
        <src>/static/wx/wx.js</src>
        <src>/static/zepto/zepto.min.js</src>
        <src>/static/activity/cover.js</src>
        <src>/static/sweetalert/sweetalert.min.js</src>
    </pack:script>

    <script>
        wx.config(${config});

        wx.ready(function () {
            wx.onMenuShareAppMessage({
                title: '我向房东打白条', // 分享标题
                desc: '${result.shareDesc}', // 分享描述
                link: '${shareUrl}', // 分享链接
                imgUrl: '${shareImgUrl}', // 分享图标
                type: 'link', // 分享类型,music、video或link，不填默认为link
                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                success: function () {
                    // 用户确认分享后执行的回调函数
                    afterShare();
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            wx.onMenuShareTimeline({
                title: '我正向房东打白条', // 分享标题
                link: '${shareUrl}', // 分享链接
                imgUrl: '${shareImgUrl}', // 分享图标
                success: function () {
                    afterShare();// 用户确认分享后执行的回调函数
                },
                cancel: function () {
                    // 用户取消分享后执行的回调函数
                }
            });
            wx.hideMenuItems({
                menuList: ["menuItem:copyUrl"]
            });
        });
    </script>
    <title>活动主页面</title>
</head>
<body ontouchstart>

<div class="wrapper">
    <div class="bg-img"><img src="<c:url value="/static/img/activity/tittle.jpg"/>"></div>

    <article class="weui_article" style="color: #ffffff">
        <p>亲:</p>

        <c:choose>
            <c:when test="${result.isRank}">
                <p>您现在正在参加租+『我向房东打白条』活动,已经有${result.my.count}位亲友帮您打了${result.bond.amount}元白条,快喊亲友来帮您接力吧,么么哒!</p>
            </c:when>
            <c:otherwise>
                <p>您现在正在参加租+『我向房东打白条』活动,已经有${result.my.count}位亲友帮您接力了,还差${10-result.my.count}位亲友,您就可以领取『房租抵用券』了,快喊亲友帮您接力吧!么么哒!</p>
            </c:otherwise>
        </c:choose>
    </article>

    <div class="bd spacing" style="margin: 0 15px">
        <a href="javascript:void(0);" id="continueBtn" class="weui_btn btn-warning">继续接力</a>
        <c:if test="${result.isRank}">
            <a href="javascript:void(0);" id="claimBtn" class="weui_btn btn-warning">领取白条</a>
        </c:if>
    </div>

    <div class="rule">
        <img src="<c:url value="/static/img/activity/main.png"/>">
    </div>

    <div id="successTip" class="cover">
        <div style="position: absolute; top: 1rem;right: 1.5rem">
            <img style="width: 2rem" src="${ctx}/static/img/activity/guide.png">
        </div>
        <div style="text-align: center;margin-top: 5em">
            <h1 style="color: #DC0B5A">恭喜您报名成功!</h1>

            <h2 style="color: #B9B9B9">点击右上角分享到朋友圈或10位朋友替您接力</h2>
        </div>
    </div>
    <div id="continueTip" class="cover">
        <div style="position: absolute; top: 1rem;right: 1.5rem">
            <img style="width: 2rem" src="${ctx}/static/img/activity/guide.png">
        </div>
        <div style="text-align: center;margin-top: 5em">
            <h2 style="color: #B9B9B9">点击右上角分享到朋友圈或朋友替您接力</h2>
        </div>
    </div>
</div>

<div class="weui_dialog_alert" id="applyedTip" style="display: none;">
    <div class="weui_mask"></div>
    <div class="weui_dialog">
        <div class="weui_dialog_hd"><strong class="weui_dialog_title">领取白条成功！</strong></div>
        <div class="weui_dialog_bd" style="text-align: center">
            <h4>您已申请了『租+』房租分期,可直接使用!工作人员将在3个工作日内与您联系,或直接致电400-8585-685</h4>
        </div>
        <div class="weui_dialog_ft">
            <a href="javascript:void(0);" id="tipConfirm" class="weui_btn_dialog primary">确定</a>
        </div>
    </div>
</div>


</body>
<script>

    $(function () {
        //刚完成报名
        if (${fromApplyFlag}) {
            _system._cover("#successTip");
        }

        $("#continueBtn").on("click", continueHandler);
        $("#claimBtn").on("click", claimHandler);
        $("#tipConfirm").on("click", tipConfirmHandler);
    });

    function afterShare() {
        $("#successTip").hide();
        $("#continueTip").hide();
    }

    //继续接力
    function continueHandler() {
        _system._cover("#continueTip");
    }

    function tipConfirmHandler() {
        $("#applyedTip").hide();
    }

    //领取白条
    function claimHandler() {
        $.post('/rent/activity/claimBond',
                {openId: '${openId}'},
                function (data) {
                    if (data.resultCode == 1000) {
                        //已申请租+
                        if(data.resultCodeExt == 8888){
                            $("#applyedTip").show();
                            return;
                        }

                        location.replace('${ctx}/activity/applyInstalment');
                    } else {
                        swal("提示", data.resultMsg, "error");
                    }
                });
    }
</script>
</html>
